$(function () {
    /*资源清单模块
    * resource(str)  str-->类型
    * */
    function resource(str) {
        $.ajax({
            url: "/index/resources/queryTypeValue",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"type": str}),
            success: function (res) {
                if (res.code == "200") {
                    var html = "";
                    for (var i = 0; i < res.data.length; i++) {
                        var str = res.data[i];
                        html += '\
                    <div class="pull-left hidden-font" data-sysid="' + str.sysId + '" title="' + str.title + '">' + str.title + '</div>\
                    ';
                    }
                    $(".nav-active-content").html(html);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        })
    }

    resource(0);

    $(".nav-active").on("click", "div", function (e) {
        $(this).addClass("nav-actives").siblings().removeClass("nav-actives");
        var type = $(this).data("type");
        resource(type);
    });

    $(".nav-active-content").on("click", ".pull-left", function (e) {
        $(".resouces-detail").css("display", "block");//打开窗口
        var sysid = $(this).data("sysid");//获取id值
        $.ajax({
            url: "/index/resources/queryDetailValue",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"sysId": sysid}),
            success: function (res) {
                if (res.code == "200") {
                    $(".resouces-detail  p").html(res.data.text);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        })

    });

    $(".resouces-detail").on("click", ".close-btn", function (e) {
        $(".resouces-detail").css("display", "none");
        $(".resouces-detail  p").html("暂无数据");
    });

    /**************以上为资源清单模块******************* */


    // 地区针对性比较 添加移除clas
    $(".switch-btn span").click(function (e) {
        $(this).addClass("switch-btn-active").siblings().removeClass("switch-btn-active");
    });

    /**
     *首页中间弹窗容器
     */
    //打开容器
    $(".analysisReport").click(function (e) {
        $("#middle-container").css("display", "block");
        $("#report").prop("src", "/web/aiReport/");
    });

    //关闭容器
    $(".title-container .close-btn").click(function (e) {
        $("#middle-container").css("display", "none");
    });

    /**
     * 首页指标预警
     */
    $.ajax({
        url: "/index/earlyWarning/queryEarlyWarning",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({}),
        success: function (res) {
            if (res.code == "200") {
                $(".warning-time").html(res.data[0].date);
                var html = "";
                for (var i = 0; i < res.data.length; i++) {
                    var item = res.data[i];
                    html += '\
                         <div class="warning-title" data-sysid="' + item.sysId + '" >\
                            <span class="warning-png"></span>\
                            <p class="hidden-font" title="' + item.title + '">' + item.title + '</p>\
                            <div class="leader-info">\
                                 <div>分管领导：' + item.leadership + '</div>\
                                <div>责任单位：' + item.unitsNumber + '</div>\
                            </div>\
                         </div>\
                        ';
                }
                $(".warning-content").html(html);
            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    })
    //指标预警点击事件
    $(".warning-content").on("click", ".warning-title", function () {
        $("#myModal-warning").modal('show'); //指标弹窗
        var sysid = $(this).data("sysid");
        $.ajax({
            url: "/index/earlyWarning/getEarlyWarningPhoto",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"sysId": sysid}),
            success: function (res) {
                if (res.code == "200") {
                    var item = res.data[0];
                    $("#myModal-warning .modal-titles>p").html(item.secTitle);//标题
                    indicatorsWarning(item);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });

    //争先竞位模块
    /**
     * 地区针对性比较  gdpGross()   p->获取县城
     */
    function gdpGross(p) {
        $.ajax({
            url: "/index/indicatorScheduling/queryShopping",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({
                "currentMonth": "202206",
                "date": "202201-06",
                "area": "永泰县",
                "industryId": "A01",
                "areas": ["永泰县", p]
            }),
            success: function (res) {
                if (res.code == "200") {
                    $(".sel-bounced-item").css("display", "none");//隐藏选择弹窗
                    var html = "";
                    for (var i = 0; i < res.data.data.length; i++) {
                        var item = res.data.data[i];
                        html += '\
                             <div class="quarter">\
                                <div class="left-progress-content">\
                                     <div class="progress-item" style="width:' + item.ratio + '%;"></div>\
                                </div>\
                                <span class="quarter-name">' + item.dateName + '</span>\
                                <div class="right-progress-content">\
                                     <div class="progress-item" style="width:' + (item.otherratio == undefined ? 0 : item.otherratio) + '%;"></div>\
                                </div>\
                                <div class="row no-margin">\
                                    <div class="col-xs-6">' + item.cumulative + '亿</div>\
                                    <div class="col-xs-6">' + (item.otherCum == undefined ? 0 : item.otherCum) + '亿</div>\
                                </div>\
                            </div>\
                         ';
                    }
                    $(".progress-area").html(html);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    }

    gdpGross("大田县");//页面初始化

    $(".sel-bounced-item #determine-choose").click(function () {
        var xc = $("#sel-area option:selected").val();//获取获取县城
        gdpGross(xc);
    });
    /**
     * gdp 预测表
     */
    $.ajax({
        url: "/index/indicatorScheduling/queryValue",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({"year": "2017", "indicatorsCategory": "GDP"}),
        success: function (res) {
            if (res.code == "200") {
                var item = res.data.list;
                gdpPredict(item);
                $(".gdp-data").val(item[0].value);
                $(".one-production").val(item[1].value);
                $(".second-production").val(item[2].value);
                $(".three-production").val(item[3].value);
            } else {
                console.log("系统出错，请联系管理员");
            }
        }
    });

    //gdp点击预测事件
    $("#predict-btn").click(function () {
        var gdpData = $(".gdp-data").val();//GDP数值
        var oneProduction = $(".one-production").val();//一产
        var secondProduction = $(".second-production").val();//二产
        var threeProduction = $(".three-production").val();//三产
        if (gdpData == "" || oneProduction == "" || secondProduction == "" || threeProduction == "") {
            $("#validation-remind").html("输入框不能为空！");
            return;
        } else {
            $("#validation-remind").html("");
        }
        if (gdpData != 0 && oneProduction != 0 && secondProduction != 0 && threeProduction != 0) {
            $("#validation-remind").html("至少一个值为 0");
            return;
        } else {
            $("#validation-remind").html("");
        }

        $.ajax({
            url: "/index/indicatorScheduling/detailIndicator",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({
                "year": "2017",
                "indicatorsCategory": "GDP",
                "lists": [{"indicatorName": "GDP", "ratio": gdpData}, {
                    "indicatorName": "第一产业",
                    "ratio": oneProduction
                }, {"indicatorName": "第二产业", "ratio": secondProduction}, {
                    "indicatorName": "第三产业",
                    "ratio": threeProduction
                }]
            }),
            success: function (res) {
                if (res.code == "200") {
                    var item = res.data.list;
                    gdpPredict(item);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });


    $(".sel-bounced-item .cancel").click(function (e) {
        e.stopPropagation(); //阻止冒泡
        $(".sel-bounced-item").css("display", "none");
    });

    $(".sel-bounced").click(function (e) {
        $(".sel-bounced-item").css("display", "block");
    });

    /**
     * 首页更多指标点击显示不同指标页面
     */
    $(".indicator-item").on("click", ".hidden-font", function () {
        var url = $(this).data("url");//指标页面路径
        var title = $(this).text();//指标名
        $("#indicator-detail  .modal-titles>p").html(title);
        $(".echart-content iframe").prop("src", url);
        $("#indicator-detail").modal('show'); //指标详情图表
    });

    //更多指标选择点击显示隐藏
    $(".indicator-sel").click(function () {
        $(".indicator-item").toggle();
        $.ajax({
            url: "/index/queryIndicatorsList",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({}),
            success: function (res) {
                if (res.code == "200") {
                    var html = "";
                    for (var i = 0; i < res.data.length; i++) {
                        var item = res.data[i];
                        html += '\
                        <p class="hidden-font" data-id="' + item.industryId + '" title="' + item.name + '"  data-url="' + item.url + '">\
                             <em> ● </em>' + item.name + '\
                        </p>\
                     ';
                    }
                    $(".indicator-item").html(html);
                }
            }
        });
    });

    // 点击除按钮和弹框之外任意地方隐藏指标选择
    $("body").click(function (e) {
        if (!$(e.target).closest(".indicator-sel ,.indicator-item").length) {
            $(".indicator-item").hide();
        }
    });


    //点击我的收藏
    $(".my-collection").click(function () {
        $(".collection").toggle();
    });

    // 点击除按钮和弹框之外任意地方隐藏指标选择
    $("body").click(function (e) {
        if (!$(e.target).closest(".my-collection ,.collection").length) {
            $(".collection").hide();
        }
    });


    // 右侧边栏，关闭预测弹窗
    $(".predict-input .close-window").click(function () {
        $(".predict-input").css("display", "none");
    });
    //侧边栏产业调度表 预测弹框
    // 一产预测
    $(".dispatch-one  .yellow-btn").click(function () {
        $(".predict-input").css("display", "block");
    });

    // 二产预测弹窗
    $(".dispatch-two  .yellow-btn").click(function () {
        $(".predict-input").css("display", "block");
        $(".sure1").css("display", "block");
        $(".sure2").css("display", "none");

        var html = "";
        for (var i = 0; i < twoProductionData.list.length; i++) {
            var arr = twoProductionData.list[i];
            html += '\
                    <div class="predict-item">\
                        <p class="hidden-font" title="' + arr.name + '">' + arr.name + '</p>\
                        <p>\
                            <input class="data' + i + '"  type="number" value="' + arr.value + '" type="number" t_value="" o_value="" onkeypress="keyPress(this)" onkeyup="keyUp(this)" onblur="onBlur(this)">\
                        </p>\
                    </div>\
                ';
        }
        $(".predict-content").html(html);
    });

    //二产点击确定请求
    $(".predict-input .sure1").click(function () {
        var data0 = $(".predict-item .data0").val();
        var data1 = $(".predict-item .data1").val();
        var data2 = $(".predict-item .data2").val();
        var data3 = $(".predict-item .data3").val();
        //验证提示
        if (data0 == "" || data1 == "" || data2 == "" || data3 == "") {
            $("#prompt").html("输入框不能为空！");
            return;
        } else {
            $("#prompt").html("");
        }
        if (data0 != 0 && data1 != 0 && data2 != 0 && data3 != 0) {
            $("#prompt").html("至少一个值为 0");
            return;
        } else {
            $("#prompt").html("");
        }
        $.ajax({
            url: "/index/indicatorScheduling/detailIndicator",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({
                "year": "2017",
                "indicatorsCategory": "第二产业",
                "lists": [{"indicatorName": "第二产业", "ratio": data3}, {
                    "indicatorName": "建筑业增加值",
                    "ratio": data2
                }, {"indicatorName": "规模以下工业增加值", "ratio": data1}, {"indicatorName": "规模以上工业增加值", "ratio": data0}]
            }),
            success: function (res) {
                twoProductionData = res.data;//二产数据全局变量
                if (res.code == "200") {
                    var item = res.data;
                    var key = "第二产业";
                    $(".dispatch-two .rate").html(item.value + "%");

                    /**
                     *  dispatch(el,item,key)
                     *  el = 元素ID  item= 图表数据  key = 判断参数
                     */
                    dispatch('dispatch-two', item, key);

                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });

    // 三产预测弹窗
    $(".dispatch-three  .yellow-btn").click(function () {
        $(".predict-input").css("display", "block");
        $(".sure1").css("display", "none");
        $(".sure2").css("display", "block");

        var html = "";
        for (var i = 0; i < threeProductionData.list.length; i++) {
            var arr = threeProductionData.list[i];
            html += '\
                    <div class="predict-item">\
                        <p class="hidden-font" title="' + arr.name + '">' + arr.name + '</p>\
                        <p>\
                            <input class="data' + i + '"  type="number" value="' + arr.value + '" type="number" t_value="" o_value="" onkeypress="keyPress(this)" onkeyup="keyUp(this)" onblur="onBlur(this)">\
                        </p>\
                    </div>\
                ';
        }
        $(".predict-content").html(html);
    });
    /**
     * 产业分行业分析调度
     */
    //产业分行业分析调度 三产点击确定请求
    $(".predict-input .sure2").click(function () {
        var data0 = $(".predict-item .data0").val();
        var data1 = $(".predict-item .data1").val();
        var data2 = $(".predict-item .data2").val();
        var data3 = $(".predict-item .data3").val();
        var data4 = $(".predict-item .data4").val();
        var data5 = $(".predict-item .data5").val();
        var data6 = $(".predict-item .data6").val();
        //验证提示
        if (data0 == "" || data1 == "" || data2 == "" || data3 == "" || data4 == "" || data5 == "" || data6 == "") {
            $("#prompt").html("输入框不能为空！");
            return;
        } else {
            $("#prompt").html("");
        }
        if (data0 != 0 && data1 != 0 && data2 != 0 && data3 != 0 && data4 != 0 && data5 != 0 && data6 != 0) {
            $("#prompt").html("至少一个值为 0");
            return;
        } else {
            $("#prompt").html("");
        }
        $.ajax({
            url: "/index/indicatorScheduling/detailIndicator",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({
                "year": "2017",
                "indicatorsCategory": "第三产业",
                "lists": [{"indicatorName": "第三产业", "ratio": data6}, {
                    "indicatorName": "其他服务业",
                    "ratio": data5
                }, {"indicatorName": "房地产业", "ratio": data4}, {
                    "indicatorName": "金融业",
                    "ratio": data3
                }, {"indicatorName": "住宿和餐饮业", "ratio": data2}, {
                    "indicatorName": "交通运输、仓储和邮政业",
                    "ratio": data1
                }, {"indicatorName": "批发和零售业", "ratio": data0}]
            }),
            success: function (res) {
                threeProductionData = res.data;//二产数据全局变量
                if (res.code == "200") {
                    var item = res.data;
                    var key = "第三产业";
                    $(".dispatch-three .rate").html(item.value + "%");

                    /**
                     *  dispatch(el,item,key)
                     *  el = 元素ID  item= 图表数据  key = 判断参数
                     */
                    dispatch('dispatch-three', item, key);

                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });

    /**
     *以下为首页三产七大
     * */
    // 三大七产业指标子集
    $(".scqd-content").on("click", ".three-col", function () {
        var el = $(this).parent().next().toggle();
        var sysid = $(this).data("id");
        $.ajax({
            url: "/web/thirdIndustry/getindexmore",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"dateTime": "", "indexCode": sysid}),
            success: function (res) {
                var html = "";
                for (var i = 0; i < res.data.detailList.length; i++) {
                    var item = res.data.detailList[i];
                    html += '\
                        <div class="item-content-items" data-id="' + item.indexCode + '" data-title="' + item.indexName + '">\
                           <div class="first-col" >\
                               <p>' + item.indexName + '</p>\
                               <p>\
                                   增长：<em>' + item.increase + '%</em>\
                               </p>\
                           </div>\
                           <div class="second-col">\
                              <p>第 <em>' + item.jdRank + '</em> 名</p>\
                              <p>\
                                 累计：<em>' + item.total + '' + item.totalUnit + '</em>\
                              </p>\
                           </div>\
                      </div>\
                       ';
                }
                el.html(html);
            }

        });
    });

    //三大七产业指标点击显示隐藏
    $(".production-tag").click(function () {
        $(".scqd-content").toggle();
        $.ajax({
            url: "/web/thirdIndustry/getindex",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"dateTime": ""}),
            success: function (res) {
                var html = "";
                for (var i = 0; i < res.data.resList.length; i++) {
                    var item = res.data.resList[i];
                    html += '\
                        <div class="scqd-item">\
                             <div class="scqd-content-title">\
                                   <div class="first-col" data-id="' + item.indexCode + '" data-title="' + item.indexName + '" >\
                                       <p>' + item.indexName + '</p>\
                                       <p>\
                                           增长：<em>' + item.factIncrease + '%</em>\
                                       </p>\
                                   </div>\
                                   <div class="second-col">\
                                        <p>' + item.department + '</p>\
                                        <p>\
                                            累计：<em>' + item.factTotal + '' + item.factTotalUnit + '</em>\
                                        </p>\
                                    </div>\
                                    <div class="three-col" data-id="' + item.indexCode + '">\
                                        <p>更多</p>\
                                    </div>\
                             </div>\
                             <div class="item-content" hidden>\
                              </div>\
                        </div>\
                       ';
                }
                $(".scqd-content").html(html);
            }

        });

    });

    // 点击除按钮和弹框之外任意地方隐藏三七
    $("body").click(function (e) {
        if (!$(e.target).closest(".production-tag,.scqd-content").length) {
            $(".scqd-content").hide();
        }
    });

    /*
    *三产七大模态框详情 sdqcRequest()  =>三大七产请求函数
    * */
    function sdqcRequest(sysid, title) {
        $.ajax({
            url: "/web/thirdIndustry/getindexdetail",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"dateTime": "", "indexCode": sysid}),
            success: function (res) {
                $(".dashboard-ranking").css("display", "block");
                $(".hide-finish-situation").css("display", "block");

                $("#seven-production .modal-titles>p").html(title);
                var oneRes = res.data.resOne;//全市排名情况
                var twoRes = res.data.resTwo;//总体完成情况
                var threeRes = res.data.resThree;//指标历史情况

                sevenProduction(oneRes);
                historySitation(threeRes);
                if (twoRes != undefined) {
                    doubleDashboard("dashboard-1", twoRes.factFinishIncrease, "增幅", twoRes.increaseTarget, twoRes.factFinishIncreaseUnit); //增幅仪表盘
                    doubleDashboard("dashboard-2", twoRes.factFinishTotal, "总量", twoRes.totalTarget, twoRes.factFinishTotalUnit) //总量仪表盘
                    $("#finish-rank").html("第" + twoRes.rank + "名");
                } else {
                    $(".dashboard-ranking").css("display", "none");
                    $(".hide-finish-situation").css("display", "none");
                }
            }

        });
    }

    //点击最外层
    $(".scqd-content").on("click", ".scqd-content-title .first-col", function () {
        var sysid = $(this).data("id");//获取id
        var title = $(this).data("title");//标题名

        $("#seven-production").modal('show'); //点击标题显示指标详情图表
        $(".scqd-content").hide();

        sdqcRequest(sysid, title);
    });

    //点击最内层
    $(".scqd-content").on("click", ".item-content  .item-content-items", function (e) {
        var sysid = $(this).data("id");//获取id
        var title = $(this).data("title");//标题名

        $("#seven-production").modal('show'); //点击子集显示指标详情图表
        $(".scqd-content").hide();

        sdqcRequest(sysid, title);

    });

    /**
     * 以上为三产七大模态框详情*************************************************************************
     */

    //首页中间模块
    /**
     * 首页主要经济指标情况  初始化
     */

    $.ajax({
        url: "/index/indicatorBreakdown/queryHaveValue",
        type: "POST",
        dataType: "json", //返回数据形式为json
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({"industryId": "", "area": "永泰县"}),
        success: function (res) {
            if (res.code == "200") {
                var times = res.data.date;
                indicatorSel(times);//调用最新时间指标

                var year = times.substring(0, 4);//年份
                var month = times.substring(4, 6);//月份
                $("#time-select>button").html(year + "年" + month + "月");//赋值最新时间
            }
        }
    });

    //首页时间选择事件
    $("#time-select  .btn-yellow").click(function () {
        var year = $("#time-select  .select-year>option:selected").val().toString();
        var month = $("#time-select  .select-month>option:selected").val().toString();
        var times = year + month;
        $("#time-select .btn-default").html(year + "年" + month + "月");//获取选择时间重新赋值
        indicatorSel(times);
        $("#time-select").removeClass("open");//关闭时间选择弹窗
    });


    /***
     /*指标
     * indicatorSel(newDate)
     * @param newDate
     */
    function indicatorSel(newDate) {
        $.ajax({
            url: "/index/indicatorBreakdown/queryIndustryNameList",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"date": newDate, "area": "永泰县", "state": "1"}),
            success: function (res) {
                if (res.code == "200") {
                    var html = "";
                    for (var i = 0; i < res.data.length; i++) {
                        var item = res.data[i];
                        if (item.ratio == 0) {
                            item.ratio = '-';
                        }
                        if (item.cumulative == '0.0亿元') {
                            item.cumulative = '-';
                        }
                        html += '\
                         <div class="col-xs-6">\
                               <p class="indicators-title" data-idname="' + item.industryId + '" data-url="' + item.url + '">' + item.industryName + '</p>\
                               <div>\
                                      <img class="indicators-icon-1" src="img/icon_' + i + '.png" alt="图片加载中">\
                                     <div class="data-show clear" style="display:inline-block;position: relative;">\
                                         <div class="growths-rate pull-left">\
                                             <p>增长率</p>\
                                             <p>' + item.ratio + '  %</p>\
                                         </div>\
                                         <p style="display:inline-block;font-size: 25px;position: absolute;top:0;left:46%;">|</p>\
                                        <div class="accumulative pull-right">\
                                           <p align="right">累计数</p>\
                                     <p>' + (item.cumulative) + ' </p>\
                                 </div>\
                                 </div>\
                             </div>\
                         </div>\
                         ';
                    }
                    $(".indicators-content").html(html);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    }


    //主要指标标题点击事件
    $(".indicators-content").on("click", ".indicators-title", function () {
        var url = $(this).data("url");//页面路径
        var title = $(this).text();//指标名
        $("#indicator-detail  .modal-titles>p").html(title);
        $(".echart-content iframe").prop("src", url);

        $("#indicator-detail").modal('show'); //指标详情图表
    });

    // 服务左侧侧边栏
    $(".sleect-service").on("click", "div", function (e) {
        $(this).addClass("selected-service").siblings().removeClass("selected-service");
    });


    //左侧侧边栏弹窗 tab栏切换 data-type 从左到右依次 2 3 4 5
    $(".sel-unit").on("click", "div", function (e) {
        $(".visist-detail").css("display", "none");//关闭弹窗
        $(this).addClass("selected-unit").siblings().removeClass("selected-unit");
        var types = $(this).data("type");
        $("#types").html(types);
        var times = "";
        registryRender(types, times);
    });

    //走访登记选择时间
    $(".layer-left  .time-select  .btn-yellow").click(function () {
        var year = $(".layer-left  .select-year>option:selected").val().toString();
        var month = $(".layer-left  .select-month>option:selected").val().toString();
        var times = year + month;
        $(".layer-left  .btn-default").html(year + "年" + month + "月");//获取选择时间重新赋值
        var types = $("#types").html();
        registryRender(types, times);
        $(".time-select").removeClass("open");//关闭时间选择弹窗
    });


    // 首页排名按钮
    $(".ranking-tag").click(function (e) {
        $("#ranking-moal").modal('show');
        $.jgrid.defaults.styleUI = 'Bootstrap';

        mydata = "";
        $.ajax({
            url: "/index/indicatorBreakdown/queryRank",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"date": "", "area": "永泰县"}),
            success: function (res) {
                if (res.code == "200") {
                    mydata = res.data;
                    $("#table_list_1").jqGrid({
                        data: mydata,
                        datatype: "local",
                        height: 518,
                        autowidth: true,
                        multiselect: false,
                        // shrinkToFit: true,
                        rowNum: 14,
                        rowList: [30],
                        colNames: [' ', '排名情况', '累计绝对值', '增长率(%)'],
                        colModel: [{
                            name: 'industryName',
                            index: 'industryName',
                            width: 200,
                            // sorttype: "int"
                        }, {
                            name: 'rank',
                            index: 'rank',
                            align: "center",
                            width: 100,
                            sorttype: "int",//必须加这个才能准确排名
                            // sorttype: "date",
                            // formatter: "date"
                        },
                            {
                                name: 'cumulative',
                                index: 'cumulative',
                                sortable: false,//取消排名按钮
                                width: 200
                            },
                            {
                                name: 'ratio',
                                index: 'ratio',
                                sortable: false,
                                width: 80,
                                // align: "right",
                                // sorttype: "float",
                                // formatter: "number"
                            }
                        ],
                        pager: "#pager_list_1",
                        viewrecords: true,
                        hidegrid: false
                    });
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    });

    // 县领导走访 详细弹窗
    //关闭县领导走访 详细弹窗
    $(".visist-detail").on("click", ".close-btn ", function () {
        $(".visist-detail").css("display", "none");
    });

    //显示县领导走访 详细弹窗
    $(".visit-data").on("click", ".clearfix", function () {
        var id = $(this).data("id");
        $(".visist-detail").css("display", "block");
        $.ajax({
            url: "/web/interview/getregisterbyid",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"sysId": id}),
            success: function (res) {
                var item = res.data;
                var html = "";
                html += '\
                     <div class="content-1">\
                            <p class="left-border-title">基本情况</p>\
                            <div class="row">\
                                <div class="col-xs-4">企业名称</div>\
                                <div class="col-xs-8 hidden-font  enterprise-name" title="' + item.contactBusiness + '">\
                                    ' + item.contactBusiness + '\
                                </div>\
                                </div>\
                            </div>\
                            <div class="row">\
                                <div class="col-xs-4">挂钩领导</div>\
                                <div class="col-xs-8">' + item.userName + '</div>\
                            </div>\
                            <div class="row">\
                                <div class="col-xs-4">当月走访</div>\
                                <div class="col-xs-8">' + item.interviewCountThisMonth + ' 次</div>\
                        </div>\
                      </div>\
                      <div class="content-2">\
                             <p class="left-border-title">详细情况</p>\
                              <div class="detail-item">\
                                    <p class="subtitle"><em> ● </em> 挂钩企业面临的问题和困难</p>\
                                    <div class="detail-show">\
                                           ' + item.businessProblem + '\
                                    </div>\
                              </div>\
                             <div class="detail-item">\
                                   <p class="subtitle"><em> ● </em> 协调解决情况</p>\
                                   <div class="detail-show">\
                                         ' + item.solveState + '\
                                  </div>\
                              </div>\
                              <div class="detail-item">\
                                    <p class="subtitle"><em> ● </em> 详细进度</p>\
                                    <div class="detail-show">\
                                         ' + item.helpExperience + '\
                                    </div>\
                              </div>\
                      </div>\
                    ';
                $(".visist-detail>.content").html(html);
            }

        });
    });
    /**
     *企查查
     * 需要md5加密
     */
    $(".visist-detail").on("click", ".enterprise-name", function () {
        var params = $(this).text();//企业名称
        var userId = $("#userId").text();//用户id
        var userMd5 = hex_md5(userId);
        var sign = hex_md5(userMd5 + "7d44f079e9051033d4e08626a865f2bf");
        var url = "https://link.qichacha.com/open/index.html#/search-company/59b25af198055be06d6908b4376829c8/" + sign + "/" + userMd5 + "?searchKey=" + params;
        window.open(url.replace(/\s*/g,""));//跳转企查查页面 replae：去除参数空格问题
    });

    /**
     * 县领导走访汇总表
     * visitSummary(item)  item =>数据参数
     */
    //点击选择年份
    $(".time-select  .btns").click(function () {
        //选择年月份
        var date = new Date;
        var year = Number(date.getFullYear());
        var year1 = year - 1;
        var year2 = year - 2;
        var text = '';
        text += '\
              <option value="-">-年份-</option>\
              <option value="' + year + '">' + year + '</option>\
              <option value="' + year1 + '">' + year1 + '</option>\
               <option value="' + year2 + '">' + year2 + '</option>\
             ';

        $(".select-year").html(text);
    });

    //点击选择年份确定
    $("#visit-summary  .time-select  .btn-yellow").click(function () {

        var year = $("#visit-summary .select-year>option:selected").val().toString();
        var month = $("#visit-summary .select-month>option:selected").val().toString();
        var yearMonth = year + month;
        $("#visit-summary .btn-default").html(year + "年" + month + "月");//选择时间赋值
        $.ajax({
            url: "/web/summary/querysummary",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"fillDate": "", "fillUnitId": "", "fillDate": yearMonth}),
            success: function (res) {
                if (res.data == undefined) {
                    $("#visit-summary .content-summary").html("暂无数据");
                    return;
                }
                if (res.code == "200") {
                    var item = res.data;
                    visitSummary(item);
                }
            }
        });
        $(".time-select").removeClass("open");//关闭时间选择弹窗
    });

    function visitSummary(item) {
        $("#visit-summary .btn-default").html(item.year + "年" + item.month + "月");//时间
        var percent = (item.businessThisMonth / item.allConnectBusiness).toFixed(2) * 100;//进度条百分比
        var html = "";
        html = '\
                         <p class="left-border-title">走访数据统计</p>\
                    <div class="row">\
                    <div class="col-xs-4">\
                    <p>本月走访企业总次数</p>\
                    <em>' + item.businessThisMonth + '</em>\
                    </div>\
                    <div class="col-xs-4">\
                    <div class="progress progress-striped active">\
                    <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="60"\
                aria-valuemin="0" aria-valuemax="100" style="width: ' + percent + '%;">\
                    </div>\
                    </div>\
                    </div>\
                    <div class="col-xs-4 no-padding">\
                    <p>县（市）区领导挂钩联系企业总数 </p>\
                <em>' + item.allConnectBusiness + '</em>\
                </div>\
                </div>\
                <p class="left-border-title">帮助企业协调解决问题情况</p>\
                    <div class="row">\
                    <div class="col-xs-12">\
                    <!-- 解决问题图表 -->\
                    <div id="solve-problem"></div>\
                    </div>\
                    </div>\
                    <p class="left-border-title">详情</p>\
                    <div class="detail-item">\
                    <p class="subtitle"><em> ● </em> 采取的主要次数和工作成效</p>\
                <div class="detail-show">\
                   ' + item.effect + '\
                </div>\
                </div>\
                <div class="detail-item">\
                    <p class="subtitle"><em> ● </em> 协调解决情况</p>\
                <div class="detail-show">\
                   ' + item.helpExperience + '\
            </div>\
                </div>\
                    ';
        $("#visit-summary .content-summary").html(html);
        solveProblem(item);//调用图表
    }

    //点击显示弹窗
    $(".sleect-service .visit-total").click(function () {
        $("#visit-summary").modal("show");//显示弹窗
        $.ajax({
            url: "/web/summary/querysummary",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"fillDate": "", "fillUnitId": "", "fillDate": ""}),
            success: function (res) {
                if (res.data == undefined) {
                    $("#visit-summary .content-summary").html("暂无数据");
                    return;
                }
                if (res.code == "200") {
                    var item = res.data;
                    visitSummary(item);
                }
            }
        });
    });

    /**
     * 以上为县领导走访汇总表************************
     */

    //修改密码
    $("#updateUpwd").click(function () {

        var userName = $("#userId").text();//用户id
        var password = $("#password").val();//旧密码
        var newPwd = $("#newPaddword").val();//新密码
        var reNewPwd = $("#confirmPassword").val();//确认密码
        if (userName == "" || password == "" || newPwd == "" || reNewPwd == "") {
            $(".error-remind").html("文本框不能为空，请重新输入");
            return;
        }
        $.ajax({
            url: "/index/editPwd",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"username": userName, "password": password, "newPwd": newPwd, "reNewPwd": reNewPwd}),
            success: function (res) {
                if (res.code == "200") {
                    $(".error-remind").html(res.message);
                    if (res.data == "1") {
                        $("#updatePassword").modal("hide");
                    }
                }

            }

        });
    });


});


// 侧边栏弹出框
window.onload = function () {

    //移动端使用touchend
    var event = navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i) ? 'touchend' : 'click';

    // 选择器
    var Q = function (id) {
        return document.getElementById(id)
    };


    //产业调度按钮侧边栏(右)
    var _right = new mSlider({
        dom: ".layer-right",
        direction: "right",
        distance: "700px" // 弹层宽度(选填，默认"60%")
    });

    Q("btnRight").addEventListener(event, function (e) {
        $(".layer-right").css("display", "block");
        _right.open();
        //二产页面初始化
        $.ajax({
            url: "/index/indicatorScheduling/queryValue",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"year": "2017", "indicatorsCategory": "第二产业"}),
            success: function (res) {
                twoProductionData = res.data;//二产数据全局变量
                if (res.code == "200") {
                    var item = res.data;
                    var key = "第二产业";
                    $(".dispatch-two .rate").html(item.value + "%");

                    /**
                     *  dispatch(el,item,key)
                     *  el = 元素ID  item= 图表数据  key = 判断参数
                     */
                    dispatch('dispatch-two', item, key);

                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
        //三产页面初始化
        $.ajax({
            url: "/index/indicatorScheduling/queryValue",
            type: "POST",
            dataType: "json", //返回数据形式为json
            contentType: 'application/json;charset=UTF-8',
            data: JSON.stringify({"year": "2017", "indicatorsCategory": "第三产业"}),
            success: function (res) {
                if (res.code == "200") {
                    threeProductionData = res.data;//三产数据全局变量
                    var key = "第三产业";
                    var item = res.data;
                    $(".dispatch-three .rate").html(item.value + "%");
                    /**
                     *  dispatch(el,item,key)
                     *  el = 元素ID  item= 图表数据  key = 判断参数
                     */
                    dispatch('dispatch-three', item, key);
                } else {
                    console.log("系统出错，请联系管理员");
                }
            }
        });
    })


    //服务按钮侧边栏(左)
    var _left = new mSlider({
        dom: ".layer-left",
        direction: "left",
        distance: "955px" // 弹层宽度(选填，默认"60%")
    });

    Q('btnLeft').addEventListener(event, function () {
        $(".layer-left").css("display", "block");
        _left.open();

        //页面初始化
        registryRender("2");

    })
}

